Repository navigation
Conversation
With validate = false, decoding tries every oneOf variant and counts the ones that convert. A JSON number such as 1.0 or 1 converted to Bool, so it matched both Float64 and Bool and decode threw. Make _decode(Bool, x) accept only a JSON boolean.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A generated oneOf decoder can throw when validation is off.
The decoder tries every variant and counts the ones that convert.
Julia converts the numbers 1.0 and 1 to Bool.
So a number matches both a number variant and a boolean variant.
The decoder then throws "oneOf value did not select exactly one variant".
Decoding with validation on works, because schema checks pick one branch.
Reproduction
Schema:
The generator emits a wrapper with
value::Union{Bool,Float64,String}.Call the generated decoder with
validate = falseand the value1.0.The call throws a
DecodeError.The value
1fails in the same way.Cause
_decode(::Type{Bool}, value)has no specific method for non-boolean input.The call falls to the generic method, which calls
convert(Bool, value).That call succeeds for 0, 1, 0.0, and 1.0.
Fix
Add two
_decodemethods forBoolinsrc/runtime.jl.They throw
DecodeErrorunless the input is a JSON boolean.The second method takes
Integer.It prevents an ambiguity with the existing
T<:Integermethod.The validating path does not change.
Tests
The new test in
test/models.jlgenerates a client from an inline spec.It decodes 1.0, 1, true, and "NaN" with validation on and off.
Each input selects exactly one variant with the correct value and type.
The test fails before the fix and passes after it.
The full suite passes.